package com.fucheng.client;

import com.fucheng.api.CalculatorService;
import com.fucheng.api.HelloService;
import com.fucheng.server.ServiceConfig;

import java.io.Serializable;

public class RpcClient implements Serializable {

    public static void main(String[] args) {

        // 构建代理工厂（内部包含 Zookeeper 服务发现 + Netty 发送）
        RpcClientProxy proxy = new RpcClientProxy();

        // 构建服务配置（接口名、版本号、服务名）
        ServiceConfig<HelloService> helloConfig =
                new ServiceConfig<>(HelloService.class, "1.0", "helloService");
        ServiceConfig<CalculatorService> calcConfig =
                new ServiceConfig<>(CalculatorService.class, "1.0", "calculatorService");

        // 获取远程代理对象
        HelloService helloService = proxy.getProxy(helloConfig);
        CalculatorService calculatorService = proxy.getProxy(calcConfig);

        // 执行远程方法调用
        String result = helloService.sayHello("Netty + Zookeeper");
        System.out.println("HelloService 返回结果：" + result);

        int sum = calculatorService.add(10, 20);
        System.out.println("CalculatorService 返回结果：10 + 20 = " + sum);
    }
}
